import requests
import unittest


class Test_Ihrm_login(unittest.TestCase):
    def test01_login(self):
        url = "http://ihrm2-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json = {
            "mobile":"13800000002",
            "password":"123456"
        }

        resp = requests.post(url = url, headers = header, json= json )
        print("登陆成功", resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

    def test02_login(self):
        url = "http://ihrm2-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json = {
            "mobile": None,
            "password": "123454"
        }

        resp = requests.post(url=url, headers = header,  json=json)
        print("手机号为空", resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json().get("success"))
        self.assertEqual(20001, resp.json().get("code"))
        self.assertIn("用户名或密码错误", resp.json().get("message"))

    def test03_login(self):
        url = "http://ihrm2-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json = {
            "mobile":"13800000002",
            "password":"123454"
        }

        resp = requests.post(url = url, headers = header, json= json )
        print("密码错误", resp.json())


        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json().get("success"))
        self.assertEqual(20001, resp.json().get("code"))
        self.assertIn("用户名或密码错误", resp.json().get("message"))